<?php
namespace App\Services\Api;

/**
 * 旧版服务号接口-积分相关接口封装
 * @package App\Services\Api
 */
class SogalBaseScoreService extends SogalBaseService
{
    /**
     * 构造函数
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * @param $params ['openid'=>'用户openid','key_type'=>'积分标识','score'=>'积分值','remark'=>'备注','key_id'=>'关联业务ID']
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function addScore($params)
    {
        $apiRs = $this->http(array_merge(['a'=>'ScoreNew','m'=>'addScore'], $params));
        if (!isset($apiRs['error'])){
            throw new \Exception('接口请求错误');
        }
        if (isset($apiRs['error']) && $apiRs['error'] != 0){
            throw new \Exception('添加积分失败：'.(!empty($apiRs['msg']) ? $apiRs['msg'] : ''));
        }
        return !empty($apiRs['data']) ? $apiRs['data'] : true;
    }
}